package com.sc.javaee.controller;

import com.sc.javaee.pojo.Categories;
import com.sc.javaee.pojo.HomeRecommendations;
import com.sc.javaee.pojo.Products;
import com.sc.javaee.pojo.Result;
import com.sc.javaee.service.CategoriesService;
import com.sc.javaee.service.HomeRecommendationsService;
import com.sc.javaee.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService ps;
    @Autowired
    HomeRecommendationsService hrs;
    @Autowired
    CategoriesService cs;
    //第一个初始化的展示推荐页面
//    @RequestMapping("/show")
//   public Result show(){
//        List<HomeRecommendations> list = hrs.show();
//        return new Result(1,"初始化成功",list);
//    }
   //根据货物类别进行分类
    @RequestMapping("/classification")
    public Result classification(@RequestBody Categories p){
        List<Products> list = cs.classification(p);
         return new Result(1,"",list);
    }
    //模糊查询 根据搜索的内容模糊匹配与之相符的title的内容的货物(要在已经查询出来的数据的情况下做模糊查询)
    @RequestMapping("/fuzzyQuery")
    public Result fuzzyQuery(@RequestBody Products p){
        List<Products> list = cs.fuzzyQuery(p);
        System.out.println(list);
        return new Result(1,"",list);
    }
    //动态查询 根据点击的分类内容进行分类
//    @RequestMapping("/dynamicQuery")
//    public Result dynamicQuery(Integer categoryId){
//        List<Products> list = cs.dynamicQuery(categoryId);
//        return new Result(1,"",list);
//    }
    //根据价格 升降排序
    @RequestMapping("/detail")
    public Result detail(Integer productId){
        Products p = ps.detail(productId);
        return new Result(1,"成功",p);
    }
    //加购功能
    @RequestMapping("/buy")
    public Result buy(Integer id){
        //在订单表里添加一个货物订单
        return new Result(1,"成功");
    }
}
